home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / PrintWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  6.1 KB  |  361 lines

  1. package java.io;
  2.  
  3. import java.security.AccessController;
  4. import java.util.Formatter;
  5. import java.util.Locale;
  6. import sun.security.action.GetPropertyAction;
  7.  
  8. public class PrintWriter extends Writer {
  9.    protected Writer out;
  10.    private boolean autoFlush;
  11.    private boolean trouble;
  12.    private Formatter formatter;
  13.    private PrintStream psOut;
  14.    private String lineSeparator;
  15.  
  16.    public PrintWriter(Writer var1) {
  17.       this(var1, false);
  18.    }
  19.  
  20.    public PrintWriter(Writer var1, boolean var2) {
  21.       super(var1);
  22.       this.autoFlush = false;
  23.       this.trouble = false;
  24.       this.psOut = null;
  25.       this.out = var1;
  26.       this.autoFlush = var2;
  27.       this.lineSeparator = (String)AccessController.doPrivileged(new GetPropertyAction("line.separator"));
  28.    }
  29.  
  30.    public PrintWriter(OutputStream var1) {
  31.       this(var1, false);
  32.    }
  33.  
  34.    public PrintWriter(OutputStream var1, boolean var2) {
  35.       this((Writer)(new BufferedWriter(new OutputStreamWriter(var1))), var2);
  36.       if (var1 instanceof PrintStream) {
  37.          this.psOut = (PrintStream)var1;
  38.       }
  39.  
  40.    }
  41.  
  42.    public PrintWriter(String var1) throws FileNotFoundException {
  43.       this((Writer)(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(var1)))), false);
  44.    }
  45.  
  46.    public PrintWriter(String var1, String var2) throws FileNotFoundException, UnsupportedEncodingException {
  47.       this((Writer)(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(var1), var2))), false);
  48.    }
  49.  
  50.    public PrintWriter(File var1) throws FileNotFoundException {
  51.       this((Writer)(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(var1)))), false);
  52.    }
  53.  
  54.    public PrintWriter(File var1, String var2) throws FileNotFoundException, UnsupportedEncodingException {
  55.       this((Writer)(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(var1), var2))), false);
  56.    }
  57.  
  58.    private void ensureOpen() throws IOException {
  59.       if (this.out == null) {
  60.          throw new IOException("Stream closed");
  61.       }
  62.    }
  63.  
  64.    public void flush() {
  65.       try {
  66.          synchronized(this.lock) {
  67.             this.ensureOpen();
  68.             this.out.flush();
  69.          }
  70.       } catch (IOException var4) {
  71.          this.trouble = true;
  72.       }
  73.  
  74.    }
  75.  
  76.    public void close() {
  77.       try {
  78.          synchronized(this.lock) {
  79.             if (this.out == null) {
  80.                return;
  81.             }
  82.  
  83.             this.out.close();
  84.             this.out = null;
  85.          }
  86.       } catch (IOException var4) {
  87.          this.trouble = true;
  88.       }
  89.  
  90.    }
  91.  
  92.    public boolean checkError() {
  93.       if (this.out != null) {
  94.          this.flush();
  95.       }
  96.  
  97.       if (this.out instanceof PrintWriter) {
  98.          PrintWriter var1 = (PrintWriter)this.out;
  99.          return var1.checkError();
  100.       } else {
  101.          return this.psOut != null ? this.psOut.checkError() : this.trouble;
  102.       }
  103.    }
  104.  
  105.    protected void setError() {
  106.       this.trouble = true;
  107.    }
  108.  
  109.    protected void clearError() {
  110.       this.trouble = false;
  111.    }
  112.  
  113.    public void write(int var1) {
  114.       try {
  115.          synchronized(this.lock) {
  116.             this.ensureOpen();
  117.             this.out.write(var1);
  118.          }
  119.       } catch (InterruptedIOException var5) {
  120.          Thread.currentThread().interrupt();
  121.       } catch (IOException var6) {
  122.          this.trouble = true;
  123.       }
  124.  
  125.    }
  126.  
  127.    public void write(char[] var1, int var2, int var3) {
  128.       try {
  129.          synchronized(this.lock) {
  130.             this.ensureOpen();
  131.             this.out.write(var1, var2, var3);
  132.          }
  133.       } catch (InterruptedIOException var7) {
  134.          Thread.currentThread().interrupt();
  135.       } catch (IOException var8) {
  136.          this.trouble = true;
  137.       }
  138.  
  139.    }
  140.  
  141.    public void write(char[] var1) {
  142.       this.write((char[])var1, 0, var1.length);
  143.    }
  144.  
  145.    public void write(String var1, int var2, int var3) {
  146.       try {
  147.          synchronized(this.lock) {
  148.             this.ensureOpen();
  149.             this.out.write(var1, var2, var3);
  150.          }
  151.       } catch (InterruptedIOException var7) {
  152.          Thread.currentThread().interrupt();
  153.       } catch (IOException var8) {
  154.          this.trouble = true;
  155.       }
  156.  
  157.    }
  158.  
  159.    public void write(String var1) {
  160.       this.write((String)var1, 0, var1.length());
  161.    }
  162.  
  163.    private void newLine() {
  164.       try {
  165.          synchronized(this.lock) {
  166.             this.ensureOpen();
  167.             this.out.write(this.lineSeparator);
  168.             if (this.autoFlush) {
  169.                this.out.flush();
  170.             }
  171.          }
  172.       } catch (InterruptedIOException var4) {
  173.          Thread.currentThread().interrupt();
  174.       } catch (IOException var5) {
  175.          this.trouble = true;
  176.       }
  177.  
  178.    }
  179.  
  180.    public void print(boolean var1) {
  181.       this.write(var1 ? "true" : "false");
  182.    }
  183.  
  184.    public void print(char var1) {
  185.       this.write(var1);
  186.    }
  187.  
  188.    public void print(int var1) {
  189.       this.write(String.valueOf(var1));
  190.    }
  191.  
  192.    public void print(long var1) {
  193.       this.write(String.valueOf(var1));
  194.    }
  195.  
  196.    public void print(float var1) {
  197.       this.write(String.valueOf(var1));
  198.    }
  199.  
  200.    public void print(double var1) {
  201.       this.write(String.valueOf(var1));
  202.    }
  203.  
  204.    public void print(char[] var1) {
  205.       this.write(var1);
  206.    }
  207.  
  208.    public void print(String var1) {
  209.       if (var1 == null) {
  210.          var1 = "null";
  211.       }
  212.  
  213.       this.write(var1);
  214.    }
  215.  
  216.    public void print(Object var1) {
  217.       this.write(String.valueOf(var1));
  218.    }
  219.  
  220.    public void println() {
  221.       this.newLine();
  222.    }
  223.  
  224.    public void println(boolean var1) {
  225.       synchronized(this.lock) {
  226.          this.print(var1);
  227.          this.println();
  228.       }
  229.    }
  230.  
  231.    public void println(char var1) {
  232.       synchronized(this.lock) {
  233.          this.print(var1);
  234.          this.println();
  235.       }
  236.    }
  237.  
  238.    public void println(int var1) {
  239.       synchronized(this.lock) {
  240.          this.print(var1);
  241.          this.println();
  242.       }
  243.    }
  244.  
  245.    public void println(long var1) {
  246.       synchronized(this.lock) {
  247.          this.print(var1);
  248.          this.println();
  249.       }
  250.    }
  251.  
  252.    public void println(float var1) {
  253.       synchronized(this.lock) {
  254.          this.print(var1);
  255.          this.println();
  256.       }
  257.    }
  258.  
  259.    public void println(double var1) {
  260.       synchronized(this.lock) {
  261.          this.print(var1);
  262.          this.println();
  263.       }
  264.    }
  265.  
  266.    public void println(char[] var1) {
  267.       synchronized(this.lock) {
  268.          this.print(var1);
  269.          this.println();
  270.       }
  271.    }
  272.  
  273.    public void println(String var1) {
  274.       synchronized(this.lock) {
  275.          this.print(var1);
  276.          this.println();
  277.       }
  278.    }
  279.  
  280.    public void println(Object var1) {
  281.       String var2 = String.valueOf(var1);
  282.       synchronized(this.lock) {
  283.          this.print(var2);
  284.          this.println();
  285.       }
  286.    }
  287.  
  288.    public PrintWriter printf(String var1, Object... var2) {
  289.       return this.format(var1, var2);
  290.    }
  291.  
  292.    public PrintWriter printf(Locale var1, String var2, Object... var3) {
  293.       return this.format(var1, var2, var3);
  294.    }
  295.  
  296.    public PrintWriter format(String var1, Object... var2) {
  297.       try {
  298.          synchronized(this.lock) {
  299.             this.ensureOpen();
  300.             if (this.formatter == null || this.formatter.locale() != Locale.getDefault()) {
  301.                this.formatter = new Formatter(this);
  302.             }
  303.  
  304.             this.formatter.format(Locale.getDefault(), var1, var2);
  305.             if (this.autoFlush) {
  306.                this.out.flush();
  307.             }
  308.          }
  309.       } catch (InterruptedIOException var6) {
  310.          Thread.currentThread().interrupt();
  311.       } catch (IOException var7) {
  312.          this.trouble = true;
  313.       }
  314.  
  315.       return this;
  316.    }
  317.  
  318.    public PrintWriter format(Locale var1, String var2, Object... var3) {
  319.       try {
  320.          synchronized(this.lock) {
  321.             this.ensureOpen();
  322.             if (this.formatter == null || this.formatter.locale() != var1) {
  323.                this.formatter = new Formatter(this, var1);
  324.             }
  325.  
  326.             this.formatter.format(var1, var2, var3);
  327.             if (this.autoFlush) {
  328.                this.out.flush();
  329.             }
  330.          }
  331.       } catch (InterruptedIOException var7) {
  332.          Thread.currentThread().interrupt();
  333.       } catch (IOException var8) {
  334.          this.trouble = true;
  335.       }
  336.  
  337.       return this;
  338.    }
  339.  
  340.    public PrintWriter append(CharSequence var1) {
  341.       if (var1 == null) {
  342.          this.write("null");
  343.       } else {
  344.          this.write(var1.toString());
  345.       }
  346.  
  347.       return this;
  348.    }
  349.  
  350.    public PrintWriter append(CharSequence var1, int var2, int var3) {
  351.       Object var4 = var1 == null ? "null" : var1;
  352.       this.write(((CharSequence)var4).subSequence(var2, var3).toString());
  353.       return this;
  354.    }
  355.  
  356.    public PrintWriter append(char var1) {
  357.       this.write(var1);
  358.       return this;
  359.    }
  360. }
  361.